﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace IveelySE.Common
{
    /// <summary>
    /// 任务父类
    /// </summary>
    public abstract class ITask
    {
        public string Name { get; set; }

        /// <summary>
        /// 任务执行线程
        /// </summary>
        private Thread thread;

        /// <summary>
        /// 执行任务
        /// </summary>
        /// <param name="sender">任务参数</param>
        public void Start(object parameters)
        {
            thread = new Thread(Sumbit);

            thread.Start(parameters);

        }

        /// <summary>
        /// 当前任务状态
        /// </summary>
        /// <returns>True正在运行</returns>
        public bool IsAlive()
        {
            return thread.IsAlive;
        }


        /// <summary>
        /// 需要提交的任务内容
        /// </summary>
        /// <param name="parameters">提交任务需要带的参数</param>
        public abstract void Sumbit(object parameters);

        /// <summary>
        /// 停止任务
        /// </summary>
        public void Stop()
        {
            thread.Abort();
        }


    }
}
